<template>
<div>
    <!-- 面包屑组件 -->
    <breadcrumb :navData="['订单管理','订单列表']"></breadcrumb>

    <!-- Card 卡片 -->
    <el-card>
        <!-- 搜索框 -->
        <el-row :gutter="20">
            <el-col :span="8"><div class="grid-content bg-purple">
                <el-input placeholder="请输入内容" v-model="query" class="input-with-select">
                    <el-button slot="append" icon="el-icon-search" @click="search"></el-button>
                </el-input>
            </div></el-col>
        </el-row>
        
        <!-- 列表 -->
        <el-table :data="list" border stripe style="width: 100%;">
            <el-table-column type="index" label="#">
            </el-table-column>
            <el-table-column prop="order_number" label="订单编号">
            </el-table-column>
            <el-table-column prop="order_price" label="订单价格">
            </el-table-column>
            <el-table-column prop="order_pay" label="是否付款">
                <template slot-scope="scope">
                    <el-tag effect="dark" v-if="scope.row.order_pay==0" size=“mini>未付款</el-tag>
                    <el-tag effect="dark" type="danger" v-else>已付款</el-tag>
                </template>
            </el-table-column>
            <el-table-column prop="is_send" label="是否发货">
            </el-table-column>
            <el-table-column prop="create_time" label="下单时间">
                <template slot-scope="scope">
                {{scope.row.create_time | formdata}}
            </template>
            </el-table-column>
            <el-table-column label="操作">
                <template slot-scope="scope">
                    <!-- 修改订单地址 -->
                    <el-tooltip class="item" effect="dark" content="修改订单地址" placement="top">
                        <el-button
                        size="mini"
                        type="primary"
                        icon="el-icon-edit"
                        @click="showEditAddress"></el-button>
                    </el-tooltip>
                    <!-- 物流信息 -->
                    <el-tooltip class="item" effect="dark" content="物流信息" placement="top">
                      <el-button @click="onSureWuliu" type="success" size="mini" icon="el-icon-location"></el-button>
                    </el-tooltip>
                </template>
            </el-table-column>
        </el-table>

        <!-- 分页 -->
        <el-pagination
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange"
          :current-page="pagenum"
          :page-sizes="[1, 2, 5, 10]"
          :page-size="pagesize"
          layout="total, sizes, prev, pager, next, jumper"
          :total="total">
        </el-pagination>

        <!-- 编辑的模态框 --> 
        <el-dialog
            title="修改收货地址"
            :visible.sync="addressVisible"
            @close="addressDialogClosed"
            >
            <!-- 添加表单 -->
            <el-form :model="addressForm" :rules="addressFormRules" ref="addressFormRef" label-width="100px">
                <el-form-item label="省市区/县" prop="address1">
                    <el-cascader :options="cityData" v-model="addressForm.address1"></el-cascader>
                </el-form-item>
                <el-form-item label="详细地址" prop="address2">
                    <el-input v-model="addressForm.address2"></el-input>
                </el-form-item>
            </el-form>
            <span slot="footer" class="dialog-footer">
                <el-button @click="addressVisible = false">取 消</el-button>
                <el-button type="primary" @click="addressVisible = false">确 定</el-button>
            </span>
        </el-dialog>

        <!-- 物流信息的模态框 -->
        <el-dialog
            title="物流进度"
            :visible.sync="progressVisible"
           >
            <el-timeline>
                <el-timeline-item v-for="(activity, index) in progressInfo" 
                    :key="index" :timestamp="activity.time">
                        {{activity.context}}
                </el-timeline-item>
            </el-timeline>
            <span slot="footer" class="dialog-footer">
                <el-button @click="progressVisible = false">取 消</el-button>
                <el-button type="primary" @click="progressVisible = false">确 定</el-button>
            </span>
        </el-dialog>
    </el-card>
</div>

</template>

<script>
import cityData from "./citydata.js" 
export default {
  components: {},
  data() {
    return {
      list: [],
      query: "", //搜索的关键词 可以为空
      pagenum: 1, //当前的页码  默认是第1页  不可以为空
      pagesize: 5, //每页显示的条数 默认是5条   不可以为空
      total: 0, //总数量

      //控制物流进度对话框的显示和隐藏
      progressVisible: false,
      //保存物流信息
      progressInfo: [],

      //编辑的数据
      //控制修改地址对话框的显示和隐藏
      addressVisible:false,
      //修改收货地址的表单
      addressForm:{
          address1:[],
          address2:''
      },
      addressFormRules:{
          address1:[{ required: true, message: '请选择省市区/县', trigger: 'blur' }],
          address2:[{ required: true, message: '请输入详细地址', trigger: 'blur' }],
      },
      //将导入的cityData数据保存起来
      cityData:cityData,

      //分类级联选择器数据绑定
      selectKeys: [],
      //分类级联选择器
      options: [],
      orderProps: {
        // expandTrigger: "hover",
        value: "cat_id",
        label: "cat_name",
        children: "children"
      }
    };
  }, // 组件方法

  methods: {
    //请求列表数据
    async getList() {
      let res = await this.$http.get("/orders", {
        params: {
          query: this.query,
          pagenum: this.pagenum,
          pagesize: this.pagesize
        }
      });
      console.log("res_list", res);
      if (res.meta.status !== 200) return this.$message.error(res.meta.msg);
      this.list = res.data.goods;
      this.total = res.data.total;
    },

    async onSureWuliu() {
      let res = await this.$http.get("/kuaidi/804909574412544580");
      if (res.meta.status !== 200) {
        return this.$message.error("获取物流进度失败!");
      }
      this.progressInfo = res.data;
      //显示对话框
      this.progressVisible = true;
    },

    //分类级联选择器change事件
    onCascaderChange() {
      console.log("当前被选中的节点id", this.selectKeys);
      //获取当前分类的参数
      this.getCategoriesAttrData();
    },

    showEditAddress() {
      //当用户点击修改收货地址按钮时触发
      this.addressVisible = true;
    },
    addressDialogClosed(){
        this.$refs.addressFormRef.resetFields()
    },

    //搜索
    search() {
      this.pagenum = 1;
      this.getList();
      this.query = "";
    },

    // 分页
    handleSizeChange(newSize) {
      this.pagesize = newSize;
      this.getList();
    },
    handleCurrentChange(current) {
      this.pagenum = current;
      this.getList();
    }
  },

  created() {
    this.getList();
  }
};
</script> 

<style  lang='scss' scoped>
</style>